package com.tony.demo.mvp.model;

import android.content.Context;

import com.puhui.lib.http.HttpParams;
import com.puhui.lib.http.HttpUtils;
import com.puhui.lib.http.retrofit.RequestResponse;
import com.puhui.lib.utils.JsonUtils;
import com.puhui.lib.utils.encrypt.MD5Util;

/**
 * Copyright:
 * Created by TangJian on 2019/4/17.
 * Description:
 * Modified:
 */

public class LoginModel extends BaseModel {

    private void login(String userName, String password, String time, Context context) {
//        time = "1555719861719";
        String flag = MD5Util.getFlag(userName, password, time + "");

        HttpParams httpParams = new HttpParams();
        httpParams.put("flag", flag);  //81527f63a8c0dc1828ef9c7434b78ef3
        httpParams.put("accountName", userName);
        httpParams.put("time", time);
        httpParams.put("password", password);
        String url = "https://www.ydyilu.com/app/platinfo/login.htm";
        HttpUtils.newInstance().post(context, url, httpParams, new RequestResponse<String>() {
            @Override
            public void onFailure(Throwable t) {
                super.onFailure(t);
            }

            @Override
            public void onSuccess(String code, String message, String result) {
            }
        });
    }

    public void getTiming(final String userName, final String password, final Context context) {
        String url = "https://www.ydyilu.com/app/timing.htm";
        HttpParams params = new HttpParams();
        params.put("verType", "1");
        HttpUtils.newInstance().post(context, url, params, new RequestResponse<String>() {
            @Override
            public void onSuccess(String code, String message, String result) {
                if (code.equals("000000")) {
                    String time = JsonUtils.getString(JsonUtils.getJsonObject(result), "time");
                    login(userName, password, time, context);
                }

            }

            @Override
            public void onFailure(Throwable t) {
            }
        });
    }
}
